#!/bin/bash

curPath=$(dirname $(readlink -f "$0"))

signPath=${curPath}/image_pack.py
dropPath=${curPath}/ci_img_headler.py
chipType=hi1910

#judge header tools is exist
if [ ! -e ${signPath} ];then
	echo "${signPath} no exist! please check!"
	exit 1
fi

if [ ! -e ${dropPath} ];then
	echo "${dropPath} no exist! please check!"
	exit 1
fi

function show_help()
{
	echo "Usage:"
	printf "%-80s\n" "	$0 <header type> <input filename> <output filename> <version> <header type>"
	printf "%-80s %-30s\n" "	$0 add  raw.img out.img <version>" "## Add header for img"
	printf "%-80s %-30s\n" "	$0 drop xxx.img raw.img"        "## Drop header for img"
	exit 1
}

#change Mode
changeMode()
{
	chmod +x ${signPath}
	chmod +x ${dropPath}
}

#check para
if [ $# -lt 3 ];then
	show_help
fi

cmdType=$1
intPath=$2
outPath=$3
addVer=$4
headerType=$5

changeMode

case ${cmdType} in
add)
	python ${signPath} -raw_img ${intPath} -out_img ${outPath} -platform ${chipType} -version ${addVer}
	if [ $? -ne 0 ];then
		echo "Add header failed!"
		exit 1
	fi
	echo "Add head success!"
	exit 0
	;;

drop)
	python ${dropPath} -img ${intPath} -raw ${outPath} --rcvr
	if [ $? -ne 0 ];then
		echo "Drop header failed!"
		exit 1
	fi
	echo "Drop head success!"
	exit 0
	;;

all)
	show_help
	;;

*)
	show_help
	;;

esac
